package com.yuncheng.oaApi.controller;

import java.util.*;
import javax.annotation.Resource;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yuncheng.vo.HttpResult;
import com.yuncheng.annotation.AutoLog;
import com.yuncheng.utils.I18nUtil;
import com.yuncheng.common.base.controller.BaseController;
import com.yuncheng.oaApi.entity.NkRsHtspjl;
import com.yuncheng.oaApi.service.INkRsHtspjlService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * @Description: 内控-合同报销记录
 * @Author: lhb
 * @Date: 2023-11-27
 * @Version: V1.0
 */
@Api(tags = "内控-合同报销记录接口")
@RestController
@RequestMapping("/api/spzx-oa/nkRsHtspjl")
public class NkRsHtspjlController extends BaseController<NkRsHtspjl, INkRsHtspjlService> {

    private static final Logger log = LoggerFactory.getLogger(NkRsHtspjlController.class);

    @Resource
    private INkRsHtspjlService nkRsHtspjlService;

    @AutoLog(value = "内控-合同报销记录-分页列表查询")
    @ApiOperation(value = "内控-合同报销记录-分页列表查询")
    @GetMapping(value = "/list")
    public HttpResult<?> queryPageList(NkRsHtspjl nkRsHtspjl, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        LambdaQueryWrapper<NkRsHtspjl> queryWrapper = new LambdaQueryWrapper<>();

        //编号
        queryWrapper.like(StringUtils.isNotBlank(nkRsHtspjl.getFhtbh()), NkRsHtspjl::getFhtbh, nkRsHtspjl.getFhtbh());

        //日期
        queryWrapper.like(StringUtils.isNotBlank(nkRsHtspjl.getFtxsj()), NkRsHtspjl::getFtxsj, nkRsHtspjl.getFtxsj());

        //金额
        queryWrapper.like(StringUtils.isNotBlank(nkRsHtspjl.getFhtje()), NkRsHtspjl::getFhtje, nkRsHtspjl.getFhtje());

        //状态
        queryWrapper.like(StringUtils.isNotBlank(nkRsHtspjl.getFhtzt()), NkRsHtspjl::getFhtzt, nkRsHtspjl.getFhtzt());

        //供应商
        queryWrapper.like(StringUtils.isNotBlank(nkRsHtspjl.getFzbgysmc()), NkRsHtspjl::getFzbgysmc, nkRsHtspjl.getFzbgysmc());


        Page<NkRsHtspjl> page = new Page<>(pageNo, pageSize);
        IPage<NkRsHtspjl> pageList = nkRsHtspjlService.page(page, queryWrapper);

        return HttpResult.ok(pageList);
    }


    @AutoLog(value = "内控-合同报销记录-添加")
    @ApiOperation(value = "内控-合同报销记录-添加")
    @PostMapping(value = "/add")
    public HttpResult<?> add(@RequestBody NkRsHtspjl nkRsHtspjl) {
        HttpResult<String> result = new HttpResult(true);
        nkRsHtspjlService.save(nkRsHtspjl);
        result.setResult(nkRsHtspjl.getId());
        result.setMessage(I18nUtil.message("save.success"));
        return result;
    }

    @AutoLog(value = "内控-合同报销记录-编辑")
    @ApiOperation(value = "内控-合同报销记录-编辑")
    @PutMapping(value = "/edit")
    public HttpResult<?> edit(@RequestBody NkRsHtspjl nkRsHtspjl) {
        nkRsHtspjlService.updateById(nkRsHtspjl);
        return HttpResult.ok(I18nUtil.message("update.success"));
    }

    @AutoLog(value = "内控-合同报销记录-通过id删除")
    @ApiOperation(value = "内控-合同报销记录-通过id删除")
    @DeleteMapping(value = "/delete")
    public HttpResult<?> delete(@RequestParam("id") String id) {
        nkRsHtspjlService.removeById(id);
        return HttpResult.ok(I18nUtil.message("delete.success"));
    }

    @AutoLog(value = "内控-合同报销记录-批量删除")
    @ApiOperation(value = "内控-合同报销记录-批量删除")
    @DeleteMapping(value = "/deleteBatch")
    public HttpResult<?> deleteBatch(@RequestParam("ids") String ids) {
        nkRsHtspjlService.removeByIds(Arrays.asList(ids.split(",")));
        return HttpResult.ok(I18nUtil.message("delete.success"));
    }

    @AutoLog(value = "内控-合同报销记录-通过id查询")
    @ApiOperation(value = "内控-合同报销记录-通过id查询")
    @GetMapping(value = "/queryById")
    public HttpResult<?> queryById(@RequestParam("id") String id) {
        NkRsHtspjl nkRsHtspjl = nkRsHtspjlService.getById(id);
        return HttpResult.ok(nkRsHtspjl);
    }

    /**
     * 数据转换
     * @param nkRsHtspjl
     */
    private void formatValue(NkRsHtspjl nkRsHtspjl){
    }
}
